package com.itheima.project.config;


import org.springframework.context.annotation.Configuration;
import org.springframework.web.filter.CharacterEncodingFilter;
import org.springframework.web.servlet.support.AbstractAnnotationConfigDispatcherServletInitializer;

import javax.servlet.FilterRegistration;
import javax.servlet.ServletContext;
import javax.servlet.ServletException;

@Configuration
public class ProjectInitConfig extends AbstractAnnotationConfigDispatcherServletInitializer{

    @Override
    public void onStartup(ServletContext servletContext) throws ServletException {
        super.onStartup(servletContext);
        FilterRegistration.Dynamic dynamic = servletContext.addFilter("encodingFilter", CharacterEncodingFilter.class);
        dynamic.setInitParameter("encoding","UTF-8");
        dynamic.addMappingForUrlPatterns(null,true,"/*");
    }

    @Override
    protected Class<?>[] getRootConfigClasses() {
        return new Class[]{springConfig.class,myBatisConfig.class};
    }

    @Override
    protected Class<?>[] getServletConfigClasses() {
        return new Class[]{springMvcConfig.class};
    }

    @Override
    protected String[] getServletMappings() {
        return new String[]{"/"};
    }
}
